import headerWrap from "../commonComponents/header.vue"
import noDataWrap from "../commonComponents/noMoreData.vue"
import loadingWrap from "../commonComponents/loadingInPage.vue"
import switchTab from "../commonComponents/switchTab.vue"

export default {
  data(){
    return {
      havePlan: false,
      switchFlag: 0,
      type: 1,
      tabData:["在办","办结"],
      pendingPageIndex: 0,
      completePageIndex: 0,
      dailyPendingList: [],
      dailyCompleteList: [],
      detailPath: null,
    }
  },
  methods: {
    init(){
      _methods.headerTitleChange(7);
      setTimeout(() => {
        this.pendingListInit();
        this.completeListInit();
      }, 100);
    },
    pendingListInit() {
      let self = this;

      _data.dailyPendingList = _methods.initMeScroll("pending", {
        //刷新
        down: {
          callback: () => {
            self.getList(1, 1);
          }
        },
        //加载更多
        up: {
          callback: () => {
            self.getList(1, 2);
          }
        }
      });

    },
    completeListInit() {

      _data.dailyCompleteList = _methods.initMeScroll("complete", {
        //刷新
        down: {
          callback: () => {
            this.getList(2, 1);
          }
        },
        //加载更多
        up: {
          callback: () => {
            this.getList(2, 2);
          }
        }
      });

    },
    //列表
    getList(listFlag, scrollFlag){
      /*
       listFlag：1.待办 2.已办 3.办结
       scrollFlag：1：刷新 2：加载更多
       */
      let self = this;
      //列表参数
      let listKey = {
        1:"dailyPendingList",
        2:"dailyCompleteList",
      }[listFlag];
      //scrollKey
      let scrollKey = {
        1:"dailyPendingList",
        2:"dailyCompleteList",
      }[listFlag];
      //页码参数
      let pageIndex = {
        1:"pendingPageIndex",
        2:"completePageIndex",
      }[listFlag];

      //待办 已办 办结，类型
      let flag = {
        1:0,
        2:1,
      }[listFlag];

      let data = {
        linkdoodID: _data.userInfo.userId,
        size: _data.pageSize,
        flag,
      };
      //ajax获取列表数据
      let ajData = (s,pg = 1) => {
        data.page = pg;
        _ajax.noLoading(_ajaxUrls.dailyReportList.url,
          data,
          (v) => {
          let val = v.result.records;
          let len = val.length;
          if (s === 1) {
            //刷新
            self[listKey] = val;
          } else {
            //加载更多
            let arr = this[listKey];
            val.forEach((i) => {
              arr.push(i);
            });
            self[listKey] = arr;
          }
          _data[scrollKey].endSuccess(len, len == _data.pageSize);
        },
          _ajaxUrls.dailyReportList.type);
      };

      if (scrollFlag === 1) {
        //刷新列表
        self[pageIndex] = 1;
        ajData(scrollFlag,self[pageIndex]);
      } else {
        // 加载更多
        self[pageIndex] = parseInt(self[pageIndex]) + 1;
        ajData(scrollFlag,self[pageIndex]);
      }
    },
    go_details(item){
      _data.userInfo.isCenterInit(()=>{
        _methods.goPath(`/dailyReportList/detail?id=${item.id}&listType=1`);
      },()=>{
        _methods.goPath(`/dailyReportList/detail?id=${item.fId}&listType=1`);
      });
    },
    switchClick(i){
      this.switchFlag = i;
    },
  },
  components: {
    headerWrap,
    noDataWrap,
    loadingWrap,
    switchTab,
  },
  mounted(){
    _vrvInit.isPush().then(()=>{
      this.init();
    },()=>{
    });
    _data.busInit.on_(() => {
      _methods.goPath("/planList");

    },7);
  },
  beforeDestroy(){
    _data.busInit.off_();
    _methods.headerRightShow();
  }
}
